package cn.doitedu.demo5;

import cn.doitedu.demo1.UserEvent_1;
import com.alibaba.fastjson.JSONObject;
import org.apache.flink.api.common.functions.RuntimeContext;
import org.apache.flink.util.Collector;

public class Rule1_Calculator implements RuleCalculator{

    JSONObject message  = new JSONObject();

    @Override
    public void init(RuntimeContext runtimeContext) {
        System.out.println("rule-001,我被初始化了");
    }

    @Override
    public void calc(UserEvent_1 eventBean, Collector<String> out) {
        // 先处理规则1
        if (eventBean.getEvent_id().equals("X")) {
            message.put("user_id", eventBean.getUid());
            message.put("hit_time", eventBean.getTimestamp());
            message.put("rule_id", "rule-001");

            out.collect(message.toJSONString());
        }

    }
}
